//
//  AmuseMenuViewCell.swift
//  DouYuZB
//
//  Created by wangpeng on 2017/3/23.
//  Copyright © 2017年 鼎商动力. All rights reserved.
//

import UIKit
private let kGameCellID = "kGameCellID"
class AmuseMenuViewCell: UICollectionViewCell {
    //MARK: - 定义属性
    var groups:[AnchorGroup]?{
        didSet{
            collectionView.reloadData()
        }
    }
    //MARK: - 控件属性
    @IBOutlet weak var collectionView: UICollectionView!
    
    //MARK: - Xib加载
    override func awakeFromNib() {
        super.awakeFromNib()
        collectionView.register(CollectionViewGameCell.NibObject(), forCellWithReuseIdentifier: kGameCellID)
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        let flowLayout = collectionView.collectionViewLayout as! UICollectionViewFlowLayout
        let itemW = collectionView.bounds.width / 4
        let itemH = collectionView.bounds.height / 2
        flowLayout.itemSize = CGSize(width: itemW, height: itemH)
    }
}

extension AmuseMenuViewCell:UICollectionViewDataSource{
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return groups?.count ?? 0
    }
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        // 1.取出Cell
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: kGameCellID, for: indexPath) as! CollectionViewGameCell
        cell.basegame = groups![indexPath.item]
        cell.clipsToBounds = true
        return cell
    }
    
}
